package com.ve.downloader;

import com.ve.downloader.utils.HexUtils;

public class ModelMap {
    private Model[] modelMap = new Model[]{
            new Model(0xE0, "12", 1, new Node[]{
                    new Node(0x00, 0x1F, "C54", ""),
                    new Node(0x60, 0x7F, "C54", "AD"),
                    new Node(0x80, 0x9F, "LE54", ""),
                    new Node(0xE0, 0xFF, "LE54", "AD")
            }),
            new Model(0xE1, "12", 1, new Node[]{
                    new Node(0x00, 0x1F, "C52", ""),
                    new Node(0x20, 0x3F, "C52", "PWM"),
                    new Node(0x60, 0x7F, "C52", "AD"),
                    new Node(0x80, 0x9F, "LE52", ""),
                    new Node(0xA0, 0xBF, "LE52", "PWM"),
                    new Node(0xE0, 0xFF, "LE52", "AD")
            }),
            new Model(0xE2, "11", 1, new Node[]{
                    new Node(0x00, 0x1F, "F", ""),
                    new Node(0x20, 0x3F, "F", "E"),
                    new Node(0x70, 0x7F, "F", ""),
                    new Node(0x80, 0x9F, "L", ""),
                    new Node(0xA0, 0xBF, "L", "E"),
                    new Node(0xF0, 0xFF, "L", "")
            }),
            new Model(0xE6, "12", 1, new Node[]{
                    new Node(0x00, 0x1F, "C56", ""),
                    new Node(0x60, 0x7F, "C56", "AD"),
                    new Node(0x80, 0x9F, "LE56", ""),
                    new Node(0xE0, 0xFF, "LE56", "AD"),
            }),
            new Model(0xD1, "12", 2, new Node[]{
                    new Node(0x20, 0x3F, "C5A", "CCP"),
                    new Node(0x40, 0x5F, "C5A", "AD"),
                    new Node(0x60, 0x7F, "C5A", "S2"),
                    new Node(0xA0, 0xBF, "LE5A", "CCP"),
                    new Node(0xC0, 0xDF, "LE5A", "AD"),
                    new Node(0xE0, 0xFF, "LE5A", "S2"),
            }),
            new Model(0xD2, "10", 2, new Node[]{
                    new Node(0x00, 0x0F, "F", ""),
                    new Node(0x60, 0x6F, "F", "XE"),
                    new Node(0x70, 0x7F, "F", "X"),
                    new Node(0xA0, 0xAF, "L", ""),
                    new Node(0xE0, 0xEF, "L", "XE"),
                    new Node(0xF0, 0xFF, "L", "X"),
            }),
            new Model(0xD3, "11", 2, new Node[]{
                    new Node(0x00, 0x1F, "F", ""),
                    new Node(0x40, 0x5F, "F", "X"),
                    new Node(0x60, 0x7F, "F", "XE"),
                    new Node(0xA0, 0xBF, "L", ""),
                    new Node(0xC0, 0xDF, "L", "X"),
                    new Node(0xE0, 0xFF, "L", "XE"),
            }),
            new Model(0xF0, "89", 4, new Node[]{
                    new Node(0x00, 0x10, "C5", "RC"),
                    new Node(0x20, 0x30, "C5", "RC"),
            }),
            new Model(0xF1, "89", 4, new Node[]{
                    new Node(0x00, 0x10, "C5", "RD+"),
                    new Node(0x20, 0x30, "C5", "RD+"),
            }),
            new Model(0xF2, "12", 1, new Node[]{
                    new Node(0x00, 0x0F, "C", "052"),
                    new Node(0x10, 0x1F, "C", "052AD"),
                    new Node(0x20, 0x2F, "LE", "052"),
                    new Node(0x30, 0x3F, "LE", "052AD"),
            }),


    };

    public Model getModelBy(byte sign) {
        for (Model model : modelMap) {
            if (model.sign == sign) {
                return model;
            }
        }
        System.err.println("invalid model :"+ HexUtils.toString(new byte[]{sign}));
        return null;
    }


    public class Node {
        byte[] keys = new byte[2];
        String[] names = new String[2];

        public Node(int b1, int b2, String name1, String name2) {
            this.keys[0] = (byte) b1;
            this.keys[1] = (byte) b2;
            this.names[0] = name1;
            this.names[1] = name2;
        }

    }

    class Model {
        byte sign;
        String prefix;
        int romratio;
        Node[] fixmap;


        public Model(int sign, String prefix, int romratio, Node[] fixmap) {
            this.sign = (byte) (sign & 0xFF);
            this.prefix = prefix;
            this.romratio = romratio;
            this.fixmap = fixmap;
        }

    }
}
